﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Input;
using HB.MVVM;
namespace PersonWatch
{
    [PropertyChanged.AddINotifyPropertyChangedInterface]
    public class VM : ViewModelBaseFody
    {
        public ObservableCollectionEx<DirWatch> WatchList { get; set; } = new ObservableCollectionEx<DirWatch>();
        public DirWatch SelectDir { get; set; }
        void Add(string dir)
        {
            if (!WatchList.Where(zz => zz.Dir == dir).Any())
            {
                DirWatch w = new DirWatch(dir);
                WatchList.Add(w);
            }
        }
        public ICommand cmdAddAllDir => GetCommand(() =>
        {
            var dirs = System.IO.DriveInfo.GetDrives();
            foreach (var d in dirs)
            {
                var dir = d.RootDirectory.ToString();
                Add(dir);

            }

        });
        public ICommand cmdAddOneDir => GetCommand(() =>
        {
            FolderBrowserDialog fb = new FolderBrowserDialog();
            if (fb.ShowDialog() == DialogResult.OK)
            {
                Add(fb.SelectedPath);
            }

        });

        public ICommand cmdDeleteOne => GetCommand(() =>
        {
            if (SelectDir != null)
            {
                WatchList.Remove(SelectDir);
            }

        });
    }
}
